package main

import (
	"context"
	"encoding/json"
	"fmt"
	zz_grpc_server "go_19/client/grpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

type message struct {
	MessageId string `json:"message_id"`
}

func main() {
	dial, _ := grpc.Dial("consul://127.0.0.1:8300/pulsar_grpc_server?wait=14s",
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
		grpc.WithTransportCredentials(insecure.NewCredentials()))

	client := zz_grpc_server.NewRemoteCallClient(dial)

	//客户端提交一次数据服务端持续计算
	//call, callErr := client.ServerStreamGrpcRemoteFunctionCall(context.Background(), &protoservice.RequestSend{StructName: "test", MethodName: "test", ReqParams: []byte("show Data")})
	//
	//if callErr!=nil{
	//	fmt.Println(callErr)
	//}
	//
	//for{
	//	recv, errorRec := call.Recv()
	//	fmt.Println(errorRec)
	//	fmt.Println(recv)
	//	if recv ==nil{
	//		break
	//	}
	//}

	m := message{
		MessageId: "CNG9AxCqGhgAIAAwAQ==",
	}
	marshal, _ := json.Marshal(m)

	result, errors := client.CallRemoteFunction(context.Background(), &zz_grpc_server.RequestMessage{PackageName: "com.zz.rpc.server.call.PulsarServerCall", MethodName: "decryptMessage", ReqParams: marshal})
	fmt.Println(result)
	fmt.Println(errors)
}
